package cn.yqn.exception;

import cn.yqn.enums.GlobalEnumCode;
import cn.yqn.result.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Component
@Slf4j
public class GlobalException {

    @ExceptionHandler(Exception.class)
    public JSONResult exceptionHandler(Exception e) {
        e.printStackTrace();
        log.info("异常捕获!");
        return JSONResult.error(GlobalEnumCode.ERROR.getMessage());
    }

    @ExceptionHandler(GlobalCustomException.class)
    public JSONResult globalCustomExceptionHandler(GlobalCustomException e) {
        e.printStackTrace();
        log.info("异常捕获!" + GlobalEnumCode.ERROR.getCode());
        return JSONResult.error(e);
    }
}
